#include "gd32f30x.h"
#include "led.h"
#include "can.h"
#include "systick.h"

#include "FreeRTOS.h"
#include "task.h"

#define LED1_TASK_PRIO    ( tskIDLE_PRIORITY + 2 )
#define LED2_TASK_PRIO    ( tskIDLE_PRIORITY + 3 )
void LED1_task(void * pvParameters);
void LED2_task(void *pvParameters);
int main(void)
{
		rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
		systick_config();//配置系统主频120M，外部8M晶振
		rcu_periph_clock_enable(RCU_AF); 
		gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE);//PB4管脚重映射
		rcu_periph_clock_enable(RCU_GPIOB);
		gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4);//初始化PB4口

        CanInit();
                
        nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);

		xTaskCreate(LED1_task, "LED1", configMINIMAL_STACK_SIZE, NULL, LED1_TASK_PRIO, NULL);
		xTaskCreate(LED2_task, "LED2", configMINIMAL_STACK_SIZE, NULL, LED2_TASK_PRIO, NULL);
	/* start scheduler */
    vTaskStartScheduler();
    while(1){
    }
}

void LED1_task(void * pvParameters)
{  
    for( ;; ){
        gpio_bit_set(GPIOB, GPIO_PIN_4);
        vTaskDelay(1000);
    }
}

void LED2_task(void * pvParameters)
{  
    for( ;; ){
        gpio_bit_reset(GPIOB, GPIO_PIN_4);
        vTaskDelay(500);
    }
}

